<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>函数柯里化</title>
</head>
<body>
    
</body>
</html>
<script>
    // 查看函数的参数个数的方法 
    function add(a,b,c,d){
        return a+b+c+d
    }
    console.log(add.length)
</script>
<script>

    // function curry(fn){
    //     if(fn.length<=1) return fn
    //     const result = (...args)=>{
    //         console.log(args.length)
    //         if(fn.length===args.length){
    //             return fn(...args)
    //         }else{
    //             return (...argsNew)=>{
    //                 return result(...args,...argsNew)
    //             }
    //         }
    //     }
    //     return result
    // }
    function curry(fn){
        if(fn.length<=0){
            return fn()
        }
        const result = (...args)=>{
            if(fn.length===args.length){
                return fn(...args)
            }else{
                return (...argsNew)=>{
                    return result(...args,...argsNew)
                }
            }
        }
        return result
    }
    function add(a,b,c,d){
        return a+b+c+d
    }
    const testadd=curry(add)
    console.log(testadd(1)(2)(3)(4))
</script>   